#!/bin/sh

# iSub.sh

APDIR=~/Desktop

##### Preparation #####

echo ========================
echo Changing Directory . . . ]
echo ========================

cd $APDIR

##### Backing up current kext #####

echo =====================================
echo Making Folder For Old Extension . . . ]
echo =====================================

mkdir OldExtensions

echo =======================================================
echo Copying Current Extension to Old Extension Folder . . . ]
echo =======================================================

cp -r /System/Library/Extensions/AppleUSBAudio.kext ~/Desktop/OldExtensions
cp -r /System/Library/Extensions/IOAudioFamily.kext ~/Desktop/OldExtensions

##### Installing files ######

echo ==========================================================
echo Copying New Extensions to /System/Library/Extensions . . . ]
echo ==========================================================
echo If asked, please enter your password . . . ]
echo ==========================================

sudo cp -r AppleUSBAudio.kext /System/Library/Extensions
sudo cp -r IOAudioFamily.kext /System/Library/Extensions
sudo cp -r AppleAC97Audio.kext /System/Library/Extensions

echo ====================================
echo Changing Extension Permissions . . . ]
echo ====================================

sudo chmod -R 755 /System/Library/Extensions/AppleUSBAudio.kext
sudo chmod -R 755 /System/Library/Extensions/IOAudioFamily.kext
sudo chmod -R 755 /System/Library/Extensions/AppleAC97Audio.kext

echo ==============================
echo Changing Extension Owner . . . ]
echo ==============================

sudo chown -R root:wheel /System/Library/Extensions/AppleUSBAudio.kext
sudo chown -R root:wheel /System/Library/Extensions/IOAudioFamily.kext
sudo chown -R root:wheel /System/Library/Extensions/AppleAC97Audio.kext

##### Deleting extensions cache #####

echo ===============================
echo Deleting Extensions Cache . . . ]
echo ===============================

sudo rm /System/Library/Extensions.mkext
sudo rm /System/Library/Extensions.kextcache

##### End of installation, asking user to restart ######

echo
echo
echo ======================================
echo Installation complete, please restart. ]
echo ======================================